package com.yh.tea.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yh.tea.entity.Role;
import com.yh.tea.model.RoleQuery;
import com.yh.tea.service.RoleService;
import com.yh.tea.utiity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2024-02-16
 */
@RestController
@CrossOrigin
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;
    /***
     * 增加role
     */
    @PostMapping("/addRole")
    public ResponseResult addRole(@RequestBody  Role role){
        Boolean result=roleService.save(role);
        return ResponseResult.success(result?"添加成功":"添加失败",result);
    }
    /***
     * 删除role
     */
    @PostMapping("/delRole")
    public ResponseResult delRole(@RequestBody List<Long> roleIdList){
        Boolean result=roleService.removeBatchByIds(roleIdList);
        return ResponseResult.success(result?"删除成功":"删除失败",result);
    }
    /***
     *分页查询
     */
    @PostMapping("/getRoleList")
    public ResponseResult getRoleList(@RequestBody RoleQuery roleQuery){
        return roleService.getRoleList(roleQuery);
    }

    @GetMapping("/getRoles")
    public ResponseResult getRoleList(){
        return  ResponseResult.success("查询成功",roleService.list());
    }
    /***
     *修改
     */
    @PostMapping("/updateRole")
    public ResponseResult updateRole(@RequestBody Role role){
        Boolean result=roleService.update(role,new QueryWrapper<Role>().eq("id",role.getId()));
        return ResponseResult.success(result?"修改成功":"修改失败",result);
    }
    @PostMapping("/getRoleByIds")
    public ResponseResult getRoleByIds(@RequestBody List<Long> roleIdList){
        return roleService.getRoleByIds(roleIdList);
    }
}

